/**
 * 
 */
package edu.arizona.bio5.onto.modularity;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;

import uk.ac.manchester.cs.owlapi.modularity.ModuleType;
import edu.arizona.bio5.onto.decomposition.persistent.PersistentAtomicDecomposition;
import edu.arizona.bio5.onto.decomposition.persistent.file.DiskADLoader;

/**
 *
 *
 * (c) Pavel Klinov
 *
 */
public class FastModuleExtractionEval {

	static final String ONTO_FILE = "eval/CHEBI/CHEBI_20K.owl";//amphibian-taxonomy.owl.xml";
	//drosophila-gross-anatomy.owl.xml";//mouse-gross-anatomy-and-development.owl.xml";
	//c-elegans-gross-anatomy.owl.xml";
	//zebrafish-anatomy-and-development.owl.xml";//mammalian-phenotype.owl.xml";
	//mahco-an-mhc-ontology.owl.xml";//human-phenotype-ontology.owl.xml";
	//static final String ONTO_FILE = "test_data/onto/GO_10K.owl";
	static final String AD_DIR = "eval/CHEBI/chebi_20K_bot_ad";
	static final ModuleType MODULE_TYPE = ModuleType.BOT;
	private static final String CSV_FILE = "eval/tmp_eval.txt";
	
	public static void main(String[] args) throws Exception {
		
		File csvFile = new File(CSV_FILE);
		
		if (csvFile.exists()) {
			
			csvFile.delete();
		}
			
		csvFile.createNewFile();
		
		BufferedWriter writer = new BufferedWriter(new FileWriter(csvFile));

		evalOnPersistentLAD(writer);
		//decomposeAndEvalOnTheFly(writer);
		
		writer.flush();
		writer.close();
		
		//GlobalTimer.timers.print();
		System.out.println("Irrelevant count: " + SeedSigBasedModuleExtractor.IRRELEVANT_COUNT);
		System.out.println("Relevant count: " + SeedSigBasedModuleExtractor.RELEVANT_COUNT);
	}

	public static void evalOnPersistentLAD(Writer writer) throws Exception {
		//Load the AD from disk
		DiskADLoader loader = new DiskADLoader(new File(AD_DIR));
		PersistentAtomicDecomposition loaded = loader.load();
		FMERunner runner = new FMERunner();
		
		runner.setOntologyFile(new File(ONTO_FILE));
		runner.process(loaded, writer);
	}
	
	public static void decomposeAndEvalOnTheFly(Writer writer) throws Exception {
		
		OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
		OWLOntology ontology = mgr.loadOntologyFromOntologyDocument(new File(ONTO_FILE));
		DecomposeAndExtractRunner runner = new DecomposeAndExtractRunner();
		
		runner.process(ontology, mgr, writer);
	}

}